package com.fengwk.resource.controller;

import java.util.Collection;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.fengwk.resource.face.model.File;
import com.fengwk.resource.service.FileService;
import com.fengwk.support.util.ResultUtils;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

@Api(tags = "文件")
@RestController
@RequestMapping("/api/file")
public class FileController {

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private HttpServletResponse response;
	@Autowired
	private FileService resourceService;
	
	@ApiOperation(
			value = "通过文件id获取文件对象", 
			response = File.class)
	@PostMapping(value = "/getByFileId")
	public void getByFileId(
			@ApiParam(value = "文件id", required = true) @RequestParam(value = "fileId", required = true) Long fileId) {
		ResultUtils.returnJsonResult(request, response, resourceService.getByFileId(fileId));
	}
	
	@ApiOperation(
			value = "通过文件ids获取文件对象列表", 
			response = File.class)
	@PostMapping(value = "/listByFileIds")
	public void listByFileIds(
			@ApiParam(value = "文件id列表", required = true) @RequestParam(value = "fileIds", required = true) Collection<Long> fileIds) {
		ResultUtils.returnJsonResult(request, response, resourceService.listByFileIds(fileIds));
	}
	
	@ApiOperation(
			value = "获取默认头像", 
			response = File.class)
	@PostMapping(value = "/getDefaultIcon")
	public void getDefaultIcon() {
		ResultUtils.returnJsonResult(request, response, resourceService.getDefaultIcon());
	}
	
}
